﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Activities;
using Microsoft.TeamFoundation.VersionControl.Client;
using System.IO;
using Microsoft.TeamFoundation.VersionControl.Common;
using Microsoft.TeamFoundation.Build.Client;

namespace BDV.TfsCustomActivities.BuildTasks
{
    [BuildActivity(HostEnvironmentOption.All)]
    public sealed class UndoWorkSpace : CodeActivity
    {
        // Define an activity input argument of type string

        [RequiredArgument]
        public InArgument<Workspace> WorkSpace { get; set; }

        // If your activity returns a value, derive from CodeActivity<TResult>
        // and return the value from the Execute method.
        protected override void Execute(CodeActivityContext context)
        {
            // Obtain the runtime value of the Text input argument
            Workspace workSpace = context.GetValue(this.WorkSpace);

            var pendings = workSpace.GetPendingChanges();

            if (pendings != null && pendings.Any())
                workSpace.Undo(pendings);
        }
    }
}
